package com.czk.index;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;

import java.io.IOException;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/6/13 13:46
 */
public class CreateIndex {
    public static void main(String[] args) throws IOException {
        // 创建客户端
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost("localhost", 9200, "http")
                )
        );
        // 创建索引对象
        CreateIndexRequest createIndexRequest = new CreateIndexRequest("user_2");
        // 创建
        CreateIndexResponse response = client.indices().create(createIndexRequest, RequestOptions.DEFAULT);
        // 拿到响应状态
        boolean b = response.isShardsAcknowledged();
        System.out.println(b);
    }
}
